package com.Nuyoah.demo01.DTO.common;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true) // 关键：忽略未知字段，防止解析失败[3](@ref)
public class ChatResponse {

    private List<Choice> choices;

    // 保留您原有的构造和方法
    public ChatResponse() {}
    public ChatResponse(List<Choice> choices) { this.choices = choices; }
    public List<Choice> getChoices() { return choices; }
    public void setChoices(List<Choice> choices) { this.choices = choices; }
    public List<Choice> choices() { return choices; } // 您代码中正在使用的方法

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Choice {
        private Message message;
        private Delta delta;
        @JsonProperty("finish_reason")
        private String finishReason;

        // 保留您原有的构造和方法
        public Choice() {}
        public Message getMessage() { return message; }
        public void setMessage(Message message) { this.message = message; }
        public Choice(Delta delta, String finishReason) {
            this.delta = delta;
            this.finishReason = finishReason;
        }
        public Delta getDelta() { return delta; }
        public void setDelta(Delta delta) { this.delta = delta; }
        public String getFinishReason() { return finishReason; }
        public void setFinishReason(String finishReason) { this.finishReason = finishReason; }
        public Delta delta() { return delta; } // 您代码中正在使用的方法
        public Message message() { return message; }
        /**
                * 安全获取内容的方法，供需要时使用
         */
        public String getSafeContent() {
            return (this.delta != null) ? this.delta.getContent() : null;
        }
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Delta {
        private String content;
        private String role; // 流式响应中可能包含角色

        // 保留您原有的构造和方法
        public Delta() {}
        public Delta(String content) { this.content = content; }
        public String getContent() { return content; }
        public void setContent(String content) { this.content = content; }
        public String content() { return content; } // 您代码中正在使用的方法
        public String getRole() { return role; }
        public void setRole(String role) { this.role = role; }
    }
}